import React, { Component } from 'react';
import { Modal, message, Col, Row, Tag } from 'antd';

export default class SetTest extends Component {
  handleSet = () => {
    const { selectedRows, dispatch } = this.props;
    const devIds = selectedRows.join(',');

    dispatch({
      type: 'dev/deviceTest',
      payload: { devIds },
      callback: () => {
        this.props.handleModalVisible(false);
        message.success('设置设备自动测试成功.');
      },
    });
  };

  render() {
    const { selectedRows } = this.props;
    const { modalVisible, handleModalVisible } = this.props;
    return (
      <Modal
        title="确定为下列设备进行测试么"
        visible={modalVisible}
        onOk={this.handleSet}
        onCancel={() => handleModalVisible(false)}
      >
        <Row style={{ width: '100%' }}>
          {selectedRows.map(item => (
            <Col span={8}>
              <Tag>{item}</Tag>
            </Col>
          ))}
        </Row>
      </Modal>
    );
  }
}
